<template>
  <div>
<!--    获取共享数据的方式1：通过this.$store.state.count-->
    <h3>通过this.$store.state.count方式得到的state组件里的值为：{{ $store.state.count }}</h3>
    <h3>调用actions异步组件得到的返回值为：{{ flag }}</h3>
    <button @click="handleAdd()">有参+5</button>
    <button @click="havaReturn()">有参有返回</button>
  </div>
</template>
<script setup>
import {useStore,} from 'vuex';
import {ref} from 'vue';
const store = useStore();
let flag=ref(0);

// 定义handleAdd函数
function handleAdd() {
  store.commit('incrementN',5);
}

function havaReturn() {
  //调用异步的有参有返回的方法
  store.dispatch('havaReturnAsync1',5).then((res) => {
    console.log(res);
    flag.value = res;
  }).catch((error) => {
    console.error('An error occurred:', error);
  });
}
</script>